package com.hup.joystick.model.joystick;

import com.hup.joystick.config.AppConfig;
import com.hup.joystick.constant.DeviceKey.KeyType;
import com.hup.joystick.constant.DeviceKey.StandardKeys;
import lombok.NoArgsConstructor;

/**
 * 标准按键类
 *
 * @author hugan
 * @date 2020/10/23
 */
@NoArgsConstructor
public class StandardKey {

    /**
     * {@link KeyType}
     */
    public int type;
    /**
     * 按键符号, {@link StandardKeys}
     */
    public String key;
    /**
     * 幅度: {@link KeyType#STICK}时为(0,1],其他类型恒定为1
     */
    public float range;

    /**
     * {@link StandardKeys}使用
     */
    public StandardKey(int type, String key) {
        this.type = type;
        this.key = key;
    }

    public static StandardKey button(String key) {
        StandardKey res = new StandardKey(KeyType.BTN, key);
        res.range = 1;
        return res;
    }

    public static StandardKey arrow(String key) {
        StandardKey res = new StandardKey(KeyType.ARROW, key);
        res.range = 1;
        return res;
    }

    public static StandardKey stick(String key, long nativeValue) {
        StandardKey res = new StandardKey(KeyType.STICK, key);
        res.range = (nativeValue < 0 ? -nativeValue : nativeValue) / (AppConfig.STICK_RANGE + 0f);
        return res;
    }


}
